package com.project.miaosha.result;

public class Result<T> {
	private int code;
	private String msg;
	private  T data;
	
	/**
	 * 成功时候调用
	 * @param data
	 * @return
	 */
	public static <T> Result<T> success(T data){
		return new Result<T>(data);
	}
	/**
	 * 失败时候调用
	 * @param data
	 * @return
	 */
	public static <T> Result<T> error(CodeMsg code){
		return new Result<T>(code);
	}
	
	private Result(T data) {
		this.code = 0;
		this.msg = "success";
		this.data = data;
	}

	public Result(CodeMsg code) {
		if(code == null){
			return;	
		}
		this.code = code.getCode();
		this.msg = code.getMsg();
	}
	public int getCode() {
		return code;
	}
	public String getMsg() {
		return msg;
	}
	public T getData() {
		return data;
	}
	
}
